<?php
namespace app\admin\controller;

use app\home\model\CreditRecord;
use app\home\model\Member;
use think\Db;
use think\Log;

class Invitation extends Base
{
    public function index(){
        $params = request()->get();
        $where = [];
        if(check_array($params)){
            if(!empty($params['keyword'])){
                $where['uid|username|invite_uid|invite_username'] = ['like', "%{$params['keyword']}%"];
            }
        }

        $total = \app\admin\model\Invitation::getCount($where);

        $list = \app\admin\model\Invitation::getPagination($where, 15, $total, "id DESC");
        $pager = $list->render();
        $list_data=$list->all();
        $member_model=db('member');
        foreach($list_data as &$v){
        	$user_info=$member_model->where('uid',$v['invite_uid'])->find();
        	$v['user_info']=$user_info;
        	if($user_info){
	        	$parent=$member_model->where('uid',$v['uid'])->find();
	        	$v['parent']=[];
	        	$v['grand']=[];
	        	$v['parent3']=[];
	        	if($parent){
	        		$v['parent']=$parent;
	        		
	        		$grand=$member_model->where('uid',$parent['parent_uid'])->find();
	        		if($grand){
	        			$v['grand']=$grand;
	        			
	        			if($grand){
	        			    $parent3=$member_model->where('uid',$grand['parent_uid'])->find();
	        			    $v['parent3']=$parent3;
	        			}
	        		}
	        	}
        	}
        	
        }
        return $this->fetch(__FUNCTION__,[
            'list' => $list,
            'pager' => $pager,
            'total' => $total
        ]);
    }
}